<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //斐波那契数从第三位开始的数是前面两个数之和
        //使用递归求到20的斐波那契数列之和
       var a = 20
        function p(a) {
        if(a > 0){
            if(a == 1 || a ==2){
                return 1;
            }
                return p(a-1)+p(a-2);
        }
        }
        function sum(a){
            if(a == 0){
                return 0;
            }
            if(a >= 1){
                return p(a) + sum(a-1);
            }
        }
        console.log('前二十位斐波那契数之和= '+sum(20));
       
    </script>
</body>

</html>